using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Robot.Business;
using Robot.Data;
using Robot.Entities;
using ExpertPdf;
using System.IO;
using Scb.Framework;

namespace WebRobot.App_code
{
  public class OtherFileReport
  {

    #region Variable Declarations

    private string _FileName = "";

    private string _FileType = "";

    #endregion

    #region Propeties

    public string FileName
    {
      get { return _FileName; }
      set { _FileName = value; }
    }

    public string FileType
    {
      get { return _FileType; }
      set { _FileType = value; }
    }

    #endregion

    #region Help

    public bool IsDateOfReportOther(string sLine)
    {
      sLine = sLine.Trim();
      if (sLine.Contains("Report Date/Time"))
      {
        return true;
      }
      return false;
    }

    public DateTime GetDateOfReportOther(string sLine)
    {
      try
      {
        sLine = sLine.Trim();
        DateTime date = new DateTime();
        date = DateTime.Now;
        string sdate = "";
        int count = 0;
        foreach (string s in sLine.Split(' '))
        {
          if (s != "")
          {
            count++;
            if (count == 4)
            {
              sdate = s;
              break;
            }
          }
        }
      
        int year = int.Parse(sdate.Split('/')[2].Trim());
        int month = int.Parse(sdate.Split('/')[1].Trim());
        int day = int.Parse(sdate.Split('/')[0].Trim());

        date = new DateTime(year,month,day);
        return date;
      }
      catch (Exception ex)
      {
        Logger.Error("WebRobot.App_code.OtherFileReport::GetDateOfReportOther", ex);
        throw;
      }

    }

    public string GetBranchOther(string sLine)
    {
      sLine = sLine.Trim();
      string branch = "";
      string[] s = sLine.Split(' ');
      int count = 0;
      for (int i = 0; i < s.Length; i++)
      {
        if (s[i] != "")
        {
          if (count == 3)
          {
            branch = s[i];
            break;
          }
          count++;
        }
      }
      if (int.TryParse(branch, out count))
      {
        return branch;
      }
      return null;
    }

    public bool IsTransaction(string sLine)
    {
      sLine = sLine.Trim();
      int count = 0;
      foreach (string s in sLine.Split(' '))
      {
        if (s != "")
        {
          count++;
        }
      }
      if ((count == 7 && (sLine.Contains("OL") || sLine.Contains("IT") || sLine.Contains("OT"))) || (count == 8 && (sLine.Contains("OL") || sLine.Contains("IT") || sLine.Contains("OT"))))
        return true;
      return false;
    }

    public tblImportTransaction GetTransactionOther(string sLine,DateTime createdDate)
    {
      sLine = sLine.Trim();
      int count = 0;
      tblImportTransaction trax = new tblImportTransaction();

      trax.CreatedDate = createdDate;
      string[] sSplit = sLine.Split(' ');
      foreach (string s in sSplit)
      {
        if (s != "")
          count++;
      }
      #region transaction of ITT, OTT
      if (count == 7)
      {
        count = 0;
        foreach (string s in sSplit)
        {
          if (s != "")
          {
            count++;
            switch (count)
            {
              case 1:// Sl.No
                trax.SlNo = s;
                break;
              case 2://Trn Reference No
                trax.TranReferenceNo = s;
                break;
              case 3://Buy Ccr
                trax.BuyCurrency = s;
                break;
              case 4://Buy Amount
                try
                {
                  trax.BuyAmount = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
              case 5://Customer rate
                try
                {
                  trax.CusRate = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
              case 6://Sell Ccr
                trax.SellCurrency = s;
                break;
              case 7://Sell Amount
                try
                {
                  trax.SellAmount = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
            }
          }
        }
      }
      #endregion

      #region transaction of OLT
      else if (count == 8)
      {
        count = 0;
        foreach (string s in sSplit)
        {
          if (s != "")
          {
            count++;
            switch (count)
            {
              case 1:// SL.No
                trax.SlNo = s;
                break;
              case 2://Trn Reference No
                trax.TranReferenceNo = s;
                break;
              case 3://Cust CD
                trax.CustCD = s;
                break;
              case 4://Buy Ccr
                trax.BuyCurrency = s;
                break;
              case 5://Buy Amount
                try
                {
                  trax.BuyAmount = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
              case 6://Customer rate
                try
                {
                  trax.CusRate = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
              case 7://Sell Ccr
                trax.SellCurrency = s;
                break;
              case 8://Sell Amount
                try
                {
                  trax.SellAmount = decimal.Parse(s);
                }
                catch (Exception ex) { }
                break;
            }
          }
        }
      }
      #endregion

      return trax;
    }

    public bool IsBranchCodeOther(string sLine)
    {
      sLine = sLine.Trim();
      if (sLine.Contains("ACCOUNT BRANCH") && sLine.IndexOf("ACCOUNT BRANCH") == 0)
      {
        return true;
      }
      return false;
    }

    #endregion

  }
}
